package com.company.Sort2;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}21:34
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] arr = {1, 5, 8, 6, -1, 9};
        System.out.println(Arrays.toString(Ssort(arr)));
    }

    public static int[] Ssort(int[] arr){
        int temp = 0;//局部变量必须设置初始值
        int index = 0;
        for (int i = 0;i< arr.length; i++){
            index = i;
            temp = arr[i];
            for (int j = i; j < arr.length;j++){
                if (arr[j] < temp){
                    index = j;
                    temp = arr[j];
                }
            }
            if (index != i) {//减少交换次数
                arr[index] = arr[i];
                arr[i] = temp;
            }
        }
        return arr;
    }
}
